package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author FengHuan Wang
 * @Date 2025/1/3 10:53
 * @Version 1.0
 */
@RestController
@Slf4j
@RequestMapping("/user/shoppingCart")
@Api(tags = "添加购物车相关接口")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;


    /*用户添加购物车功能实现*/
    @PostMapping("/add")
    @ApiOperation("添加购物车")
    public Result addShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        log.info("用户正在添加购物车");
        shoppingCartService.addShoppingCart(shoppingCartDTO);
        return Result.success();
    }

    /*用户查看购物车功能实现*/
    @GetMapping("/list")
    @ApiOperation("查看购物车")
    public Result<List<ShoppingCart>> list(){
        List<ShoppingCart> shoppingCartList =  shoppingCartService.getByUserId();
        return Result.success(shoppingCartList);
    }

    /*用户清空购物车功能实现*/
    @DeleteMapping("/clean")
    public Result clean(){
        log.info("用户正在清空购物车");
        shoppingCartService.delete();
        return Result.success();
    }

    /*删除购物中的一个菜品功能实现*/
    @PostMapping("/sub")
    public Result delOne(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("删除购物车中的一个菜品数量");
        shoppingCartService.delOne(shoppingCartDTO);
        return Result.success();
    }
}
